package com.zzptc.tss;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.widget.GridView;
import android.widget.SimpleAdapter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class MainActivity extends AppCompatActivity {
    private List<Map<String,Object>> list;
    GridView gridView;//全局变量
    int[]tupian={};
    int[] pics={R.mipmap.tss2,R.mipmap.tss1,R.mipmap.tss3,R.mipmap.tss4,R.mipmap.tss5,R.mipmap.tss6};
    String[]titles={"通讯录","日历","照相机","时钟","游戏","短信"};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        gridView = findViewById(R.id.grid_view);
        list =new ArrayList<>();
        getData();
        String[] from={"biaoti","icon"};
        int[] to={R.id.tv_title,R.id.iv_pic};
        SimpleAdapter simpleAdapter = new SimpleAdapter(MainActivity.this, list, R.layout.item, from, to);
        gridView.setAdapter(simpleAdapter);
    }

    private void getData() {
        for (int i=0;i<titles.length;i++) {
            Map<String,Object> map =new HashMap<>();
            map.put("biaoti", titles[i]);
            map.put("icon", pics[i]);
            list.add(map);
        }

    }

}
